#!/bin/bash

function check_branch() {
    branch_name=$1
    if (git branch -l | grep $branch_name); then
        echo "fastugv will operate at git branch: $branch_name"
    else
        echo "$branch_name is not exist"
        exit 1
    fi
}

param_size=$#
if [ $param_size -eq 2 ]; then
    main_branch=main
    dev_branch=dev
    main_ver=$1
    dev_ver=$2
elif [ $param_size -eq 4 ]; then
    main_branch=$1
    main_ver=$2
    dev_branch=$3
    dev_ver=$4
else
    echo "Usage:"
    echo "fastugv <main_ver> <dev_ver>"
    echo "fastugv <as_main_branch> <main_ver> <as_dev_branch> <dev_ver>"
    exit 1
fi

check_branch $main_branch
check_branch $dev_branch

git checkout $main_branch
git merge $dev_branch
ugv $main_ver
git checkout $dev_branch
git merge $main_branch
ugv $dev_ver
git checkout $main_branch
